package com.hjh.brv

import com.drake.statelayout.StateConfig
import com.scwang.smart.refresh.header.MaterialHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

/**
 * @author： hjh
 * @createDate： 2025/6/19 10:49
 * @description：
 * @qq： 3472903821
 * @version: 1.0
 */
object Brvs {

    private fun initSmartRefresh() {
        CoroutineScope(Dispatchers.Default).launch {

            SmartRefreshLayout.setDefaultRefreshInitializer { _, layout ->
                layout.setEnableLoadMore(true)
                layout.setEnableLoadMoreWhenContentNotFull(true)
            }

            SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout ->
                layout.setEnableHeaderTranslationContent(true)
                MaterialHeader(context).setColorSchemeResources(
                    com.hjh.res.R.color.blue,
                    com.hjh.res.R.color.blue,
                    com.hjh.res.R.color.blue
                )
            }

            SmartRefreshLayout.setDefaultRefreshFooterCreator { context, layout ->
                layout.setEnableFooterFollowWhenNoMoreData(true)
                layout.setEnableFooterTranslationContent(true)
                layout.setFooterHeight(153f)
                layout.setFooterTriggerRate(0.6f)
                NoStatusFooter.REFRESH_FOOTER_NOTHING =
                    context.getString(R.string.srl_footer_nothing)
                NoStatusFooter(context).apply {
                    setAccentColorId(com.hjh.res.R.color.colorTextPrimary)
                    setTextTitleSize(16f)
                }
            }
        }
    }

    fun initBrv() {
        initSmartRefresh()
        CoroutineScope(Dispatchers.Default).launch {
            StateConfig.apply {
                emptyLayout = R.layout.layout_null
                errorLayout = R.layout.layout_null
                loadingLayout = R.layout.layout_loading
            }
        }
    }
}